home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / Assertions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-16  |  3.5 KB  |  146 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Assertions.h
  3.  
  4.     Contains:    Assertion macros.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #ifndef _ASSERTIONS_
  28. #define _ASSERTIONS_
  29.  
  30. extern void        AssertMsg( char* msg, char* file, int line );
  31.  
  32. #ifdef _DEBUG
  33.     #define DECLARE_DEBUG_START        unsigned long    qDebugStart
  34.     #define DECLARE_DEBUG_END        unsigned long    qDebugEnd
  35.     
  36.     #define DEFINE_DEBUG_START( mark ) \
  37.         qDebugStart = mark
  38.     
  39.     #define DEFINE_DEBUG_END( mark )    \
  40.         qDebugEnd = mark
  41.     
  42.     #define CHECK_DEBUG_START( mark )    \
  43.         do { if ( ( qDebugStart != mark ) ) AssertMsg( "Trashed Object", __FILE__, __LINE__); } while( 0 )
  44.     
  45.     #define CHECK_DEBUG_END( mark )    \
  46.         do { if ( ( qDebugEnd != mark ) ) AssertMsg( "Trashed Object", __FILE__, __LINE__); } while( 0 )
  47.  
  48.     #define DEBUG_MARK_FREE( s, c, n )    memset( s, c, n )
  49.     #define DEBUG_MARK_NEW( s, c, n ) memset( s, c, n )
  50.     #define DEBUG_FREE_CHAR        0xEF
  51.     #define DEBUG_NEW_CHAR        0xED
  52.     #define DEBUG_FREE_SHORT    0xEFEF
  53.     #define DEBUG_NEW_SHORT        0xEDED
  54.     #define DEBUG_FREE_LONG        0xEFEFEFEF
  55.     #define DEBUG_NEW_LONG        0xEDEDEDED
  56.     
  57. #else
  58.     #define DECLARE_DEBUG_START
  59.     #define DECLARE_DEBUG_END
  60.     #define DEFINE_DEBUG_START( mark )    
  61.     #define DEFINE_DEBUG_END( mark )    
  62.     #define CHECK_DEBUG_START( mark )    
  63.     #define CHECK_DEBUG_END( mark )
  64.  
  65.     #define DEBUG_MARK_FREE( s, c, n )
  66.     #define DEBUG_MARK_NEW( s, c, n )
  67.     #define DEBUG_FREE_CHAR
  68.     #define DEBUG_NEW_CHAR
  69.     #define DEBUG_FREE_SHORT
  70.     #define DEBUG_NEW_SHORT
  71.     #define DEBUG_FREE_LONG
  72.     #define DEBUG_NEW_LONG
  73. #endif
  74.  
  75.  
  76.  
  77. #ifdef _DEBUG
  78.     #define ASSERT( condition )    \
  79.             do { if ( !(condition) )        \
  80.                 AssertMsg( "Assertion (" #condition ") failed.", __FILE__, __LINE__ );    \
  81.             } while( 0 )
  82.             
  83.     #define ASSERT_GOTO( condition, label )     \
  84.             do { if ( !(condition) )    {        \
  85.                     AssertMsg( "Assertion (" #condition ") failed.", __FILE__, __LINE__ );    \
  86.                     goto label;    \
  87.                 }    \
  88.             } while( 0 )
  89.  
  90.     #define ASSERT_ACTION( condition, action )     \
  91.             do { if ( !(condition) )    {        \
  92.                     AssertMsg( "Assertion (" #condition ") failed.", __FILE__, __LINE__ );    \
  93.                     action;    \
  94.                  }    \
  95.             } while( 0 )
  96.  
  97.     #define ASSERT_BOOLEAN( x )        if ( x != true && x != false ) AssertMsg( "Boolean assertion failed.", __FILE__, __LINE__ );
  98.  
  99. #ifdef __cplusplus
  100.     #define ASSERT_OBJECT( p )                do { if ( (p) == NULL ) \
  101.                                                     AssertMsg( "Null Object.", __FILE__, __LINE__ );    \
  102.                                                  else                \
  103.                                                      (p)->Assert();    \
  104.                                             } while( 0 )
  105.                                                 
  106.     #define ASSERT_OBJECT_NULL_OK( p )        if ( p ) (p)->Assert()
  107. #endif
  108.  
  109.     #define ASSERT_SHORT( s )        ASSERT( (s != DEBUG_NEW_SHORT) && (s != DEBUG_FREE_SHORT) )
  110.     #define ASSERT_LONG( l )        ASSERT( (l != DEBUG_NEW_LONG) && (l != DEBUG_FREE_LONG) )
  111.     #define ASSERT_CHAR( c )        ASSERT( (c != DEBUG_NEW_CHAR) && (c != DEBUG_FREE_CHAR) )
  112.     
  113.     #define DEBUG_MESSAGE( m )        DebugStr( c2pstr( ( m ) ) )
  114.     
  115. #else
  116.     #define ASSERT( condition )
  117.     
  118.     #define ASSERT_BOOLEAN( x )
  119.     
  120.     #define ASSERT_GOTO( condition, label )     \
  121.             do { if ( !(condition) )    {        \
  122.                     goto label;    \
  123.                 }    \
  124.             } while( 0 )
  125.  
  126.     #define ASSERT_ACTION( condition, action )     \
  127.             do { if ( !(condition) )    {        \
  128.                     action;    \
  129.                  }    \
  130.             } while( 0 )
  131.  
  132. #ifdef __cplusplus    
  133.     #define ASSERT_OBJECT( p )
  134.     #define ASSERT_OBJECT_NULL_OK( p )
  135. #endif
  136.     
  137.     #define ASSERT_SHORT( s )
  138.     #define ASSERT_LONG( l )
  139.     #define ASSERT_CHAR( c )
  140.     
  141.     #define DEBUG_MESSAGE( m )
  142.  
  143. #endif
  144.  
  145.  
  146. #endif